﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace MtgLib
{
    [Serializable]
    class MTGCardContent
    {
        public MTGCardContent() { }

        public string Name { get; set; }
        public string Text { get; set; }
        public string FlavorText { get; set; }
        public string Type { get; set; }
        public string ManaCost { get; set; }
        protected List<string> _editions = new List<string>();
        public List<string> Editions { get {return _editions;} }
    }

    class MTGCard
    {
        public MTGCard() {}
        public MTGCardContent cardContent {get;set;}
        public System.Drawing.Image cardPicture {get;set;}
    }

    [Serializable]
    public class DeckEntry
    {
        public string CardName
        {
            get;
            set;
        }

        public int Quantity
        {
            get;
            set;
        }

        public string Edition
        { get; set; }

        public DeckEntry()
        {

        }

        public DeckEntry(string cardName, int quantity)
        {
            CardName = cardName;
            Quantity = quantity;
        }
    }

    [Serializable]
    public class MtgDeck
    {
        public List<DeckEntry> DeckEntries
        {
            get;
            set;
        }

        public MtgDeck()
        {

        }

        public MtgDeck(List<DeckEntry> deckEntries)
        {
            DeckEntries = deckEntries;
        }

        public bool deserialize(string path)
        {
            if (!File.Exists(path))
            {
                return false;
            }
            List<DeckEntry> lde = new List<DeckEntry>();

            using (Stream infile = File.OpenRead(path))
            {
                XmlSerializer xmls2 = new XmlSerializer(typeof(List<DeckEntry>));
                lde = (List<DeckEntry>)xmls2.Deserialize(infile);
            }
            return true;
        }

        public void serialize(string path)
        {
            if (File.Exists(path)) File.Delete(path);

            XmlSerializer xms = new XmlSerializer(typeof(List<DeckEntry>));

            using (Stream outfile = File.OpenWrite(path))
            {
                xms.Serialize(outfile, this);
            }

        }

    }
}
